﻿using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.Exceptions;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YArchitech.Revit;

namespace HangerSupport
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class cmdCableTrayWeight : HYNoTranExternalCommand
	{
		public override void FilterProcess()
		{
            base.FilterViewType.Add((Autodesk.Revit.DB.ViewType)4);
            base.FilterViewType.Add((Autodesk.Revit.DB.ViewType)117);
            base.FilterViewType.Add((Autodesk.Revit.DB.ViewType)3);
			base.FilterProcess();
		}

		public override Result HYExecute()
		{
			Result result;
			try
			{
				SelectLines selectLines = new SelectLines(base.Doc, base.Sel);
				List<CableTray> source = selectLines.GetMEPCurves(new CableTrayFilter()).Cast<CableTray>().ToList<CableTray>();
				List<SystemLine> systemLines = selectLines.GetSystemLines(source.Cast<MEPCurve>().ToList<MEPCurve>());
				DlgCableTrayWeightCal dlgCableTrayWeightCal = new DlgCableTrayWeightCal(systemLines);
				dlgCableTrayWeightCal.ShowDialog();
				result = Autodesk.Revit.UI.Result.Succeeded;
			}
			catch (Autodesk.Revit.Exceptions.OperationCanceledException ex)
			{
				result = Autodesk.Revit.UI.Result.Succeeded;
			}
			catch (Exception ex2)
			{
				YJKMessageBox.Information(ex2.Message.ToString());
				result = Autodesk.Revit.UI.Result.Failed;
			}
			return result;
		}
	}
}
